<template>
	
	<view>
		<view >
		<u-navbar title-color="#fff" back-icon-color="#ffffff"
			:is-fixed="isFixed" :is-back="isBack" 
			:background="background" 
			:back-text-style="{color: '#fff'}" :title="title1" 
			:back-icon-name="backIconName" :back-text="backText"
			:border-bottom="true" @click="back">
		</u-navbar>
		
	</view>
		<u-grid :col="2" >
			<u-grid-item v-for="index in 8" :key="index" >
				<view class="image-item" @tap="selectheadpic(index)">
					<view class="image-content">
						<image style="width: 120px; height: 150px;
	background-color: #eeeeee;" mode="aspectFill" :src="'/static/headimage/'+index+'.jpg'"></image>
					</view>
				</view>
			</u-grid-item>
		</u-grid>
	</view>
</template>

<script>
	export default {
		data() { 
			return {
				//顶部导航栏
				// 顶部导航栏
				title1: '头像',
				collected:false,
				backText: '返回',
				backIconName: 'nav-back',
				right: false,
				showAction: false,
				rightSlot: false,
				useSlot: false,
				background: {
					'background-image': 'linear-gradient(45deg, #2BC3C8, #84E7B9)'
				},
				isBack: true,
				search: false,
				custom: true,
				isFixed: true,
				keyword: '',
				
				mode: 'round',
				user:{
					stuNumber:"",
					name:"",
					pwd:"",
					motto:"",
					imgAddress:'',
				},admin1:{
					name:"",
					pwd:"",
					id:"",
					imgAddress:""
				},

			}
		},
		methods: {
			back() {
				uni.navigateBack();
			},
			selectheadpic(index) {
				const shu1=uni.getStorageSync('wen');
				const shu2=uni.getStorageSync('shu01');
				if(shu1=="1"&&shu2!="12"){
					const value5 = uni.getStorageSync('user1')
					value5.imgAddress=index
					this.user.imgAddress=index
					uni.setStorageSync('user1',value5)
					uni.request({
						url: 'http://192.168.137.139:8080/storeImage',
						data: this.user,
						method: "POST",
					});
					console.log(this.user)
					uni.navigateBack()
				}if(shu1=="2"&&shu2!="12"){
					const value5 = uni.getStorageSync('admin')
					value5.imgAddress=index
					this.admin1.imgAddress=index
					uni.setStorageSync('admin',value5)
					uni.request({
						url: 'http://192.168.137.139:8080/adminStoreImage',
						data: this.admin1,
						method: "POST",
					});
					console.log(this.user)
					uni.navigateBack()
				}else{
					this.$u.toast("请登录账号后再更改头像.....")
				}
				
			}
		},
		onLoad() {
			const shu1=uni.getStorageSync('wen');
			const shu2=uni.getStorageSync('shu01');
			if(shu1=="1"&&shu2!="12"){
				const value4=uni.getStorageSync('user1');
				this.user.stuNumber=value4.stuNumber;
			}if(shu1=="2"&&shu2!="12"){
				const value4=uni.getStorageSync('admin');
				this.admin1.id=value4.id;
			}
			
		}
	}
</script>

<style scoped lang="scss">
	
</style>